package swing.frame.whiteboard;

import utils.CommonUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author ywjia
 */
public class ToolsPanel extends JPanel {
    String tool;
    JPanel panel =new JPanel();
    public ToolsPanel(){
        init();
    }
    public void init(){
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        panel.setLayout(new GridLayout(6,2,4,4));
        //向网格中添加组件
        String[] array=
                {"image/brush.png",
                "image/erase.png",
                "image/edit.png",
                "image/line.png",
                "image/spray.png",
                "image/pencil.png",
                "image/triangle.png",
                "image/rect.png",
                "image/roundrect.png",
                "image/oval.png",
                "image/rhombus.png",
                 "image/fillrect.png"
                };
        for (String s : array) {
            ImageIcon image = new ImageIcon(CommonUtils.getFileUrl(s));
            JButton button = new JButton(image);
            button.setPreferredSize(new Dimension(40, 40));
            //给按钮添加事件
            button.setActionCommand(s.substring(6, s.lastIndexOf(".")));
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
//                    button.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));
                    tool = e.getActionCommand();
                }
            });
//            button.addFocusListener(new FocusAdapter() {
//                @Override
//                public void focusLost(FocusEvent e) {
//                    super.focusLost(e);
//                    button.setUI(new BEButtonUI(). setNormalColor(BEButtonUI.NormalColor.normal));
//                }
//            });
            panel.add(button);

        }
//        panel.setPreferredSize(new Dimension(200,800));
        this.add(panel);

    }

}
